package com.sx.manage.controller.helps;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.common.util.json.JackJsonUtil;
import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.helps.IMSysQuestionService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.manage.mybatis.form.helps.MSysQuestionForm;
import com.sx.model.manage.mybatis.vo.helps.MSysQuestionVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;

/**
 * 常见问题
 * 
 * @author zwm
 *
 */
@Controller
@RequestMapping("/sysquestionInfo") // sysquestion
public class MSysQuestionController extends MBaseController {

	private Logger _log = LoggerFactory.getLogger(this.getClass());
	@Resource(name = "sysQuestionServiceImpl")
	private IMSysQuestionService mSysQuestionServiceImpl;

	/**
	 * 常见问题 添加视图
	 * 
	 * @return
	 */
	@RequestMapping(value = "question_index") // add_view_question
	public ViewAndModel add_viewSysQuestionInfo() {
		ViewAndModel viewAndModel = new ViewAndModel(request, cache);
		// 如需在添加页需要加载元素在此处增加
		viewAndModel.setViewName("help/faq/addFaq");// 修改ftl页面名称
		viewAndModel.addObject("mSysQuestionVO", new MSysQuestionVO());
		return viewAndModel;
	}

	/**
	 * 常见问题 添加 编辑
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping(value = "question_eidt") // eidt_question
	@ResponseBody
	public ResultBooleanVO add_sysQuestion(HttpServletRequest request, HttpServletResponse response){
		if (null == request) {
			return new ResultBooleanVO("sj.m.common.add.error");
		}
		String request_message = extract_param_from_request(request);
		if (null == request_message || "".equals(request_message)) {
			return new ResultBooleanVO("sj.m.common.add.error");
		}
		MSysQuestionForm form = JackJsonUtil.jsonToJavaBean(request_message, MSysQuestionForm.class);
		_log.debug("添加系统操作日志：MSysQuestionController===add_sysQuestion==formJson=" + JackJsonUtil.objToJson(form));
		if (null == form) {
			return new ResultBooleanVO("sj.m.common.add.error");
		}
		if (null != form.getId()) {
			return this.mSysQuestionServiceImpl.editMsysQuestion(form, this.loginConsumer());
		}
		return this.mSysQuestionServiceImpl.addMsysQuestion(form, this.loginConsumer());
	}

	/**
	 * 常见问题 查询
	 * 
	 * @param form
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/question_byid/{id}") // query_view_question
	@ResponseBody
	public ViewAndModel query_viewSysQuestion(MSysQuestionForm form){
		_log.debug("添加系统操作日志：MSysQuestionController===query_viewSysQuestion==formJson=" ,JackJsonUtil.objToJson(form));
		ViewAndModel viewAndModel = new ViewAndModel(request, cache);
		// 查询类
		ResultObjectVO<MSysQuestionVO> result = mSysQuestionServiceImpl.search_byId(form);
		viewAndModel.addObject("mSysQuestionVO", result.getObjVo());
		viewAndModel.setViewName("help/faq/addFaq");// 修改ftl页面名称
		return viewAndModel;
	}

	/**
	 * 查询列表视图
	 * 
	 * @return
	 */
	@RequestMapping("/search_view_question")
	public ViewAndModel search_view_question(){
		ViewAndModel viewAndModel = new ViewAndModel(request, cache);
		// 如需在添加页需要加载元素在此处增加 
		viewAndModel.setViewName("help/faq/faq");// 修改fitly页面名称
		return viewAndModel;
	}

	/**
	 * 查询 数据集合
	 * 
	 * @param form
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/question_page")
	@ResponseBody
	public ResultListVO<MSysQuestionVO> search_page_question(MSysQuestionForm form){
		_log.debug("添加系统操作日志：MSysQuestionController===search_page_question==formJson=" + JackJsonUtil.objToJson(form));
		return this.mSysQuestionServiceImpl.searchMysQuestion(form);
	}

	/**
	 * 常见问题 删除
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/question_del") // del_question
	@ResponseBody
	public ResultBooleanVO del_question(HttpServletRequest request, HttpServletResponse response){
		String request_message = extract_param_from_request(request);
		if (null == request_message || "".equals(request_message)) {
			return new ResultBooleanVO("sj.m.common.add.error");
		}
		MSysQuestionForm form = JackJsonUtil.jsonToJavaBean(request_message, MSysQuestionForm.class);
		_log.debug("添加系统操作日志：MSysQuestionController===del_question==formJson=" + JackJsonUtil.objToJson(form));
		if (null == form) {
			return new ResultBooleanVO("sj.m.common.del.error");
		}
		return this.mSysQuestionServiceImpl.delMsysQuestion(form, this.loginConsumer());
	}

}
